﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.TcCommands.TcReplace.CCoTcReplaceCmdBaseEnabler
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using UiInternalControls;


namespace DnProcessSimulateCommands.TcCommands.TcReplace;

public class CCoTcReplaceCmdBaseEnabler : ITxCommandEnabler
{
  private bool _isSupportedPlatform;

  public CCoTcReplaceCmdBaseEnabler() => this.RegisterToEvents();

  public virtual bool Enable => this._isSupportedPlatform && !TxTcStudyReservation.IsReadOnly();

  private void OnDocumentLoaded(object sender, TxDocumentCollection_DocumentLoadedEventArgs args)
  {
    this._isSupportedPlatform = TxTcUtilities.IsTcOnlinePlatform;
    if (!this._isSupportedPlatform)
      return;
    this._isSupportedPlatform = !TxEngineeringDataInternal.GlobalGetStudyFormat().Equals((object) (TxStudyFormatEnum) 1);
  }

  private void OnActiveDocumentUnloading(object sender, TxDocument_UnloadingEventArgs args)
  {
    this._isSupportedPlatform = false;
  }

  internal void RegisterToEvents()
  {
    TxApplication.DocumentCollection.DocumentLoaded += new TxDocumentCollection_DocumentLoadedEventHandler(this.OnDocumentLoaded);
    TxApplication.ActiveDocument.Unloading += new TxDocument_UnloadingEventHandler(this.OnActiveDocumentUnloading);
  }

  internal void UnregisterFromEvents()
  {
    TxApplication.DocumentCollection.DocumentLoaded -= new TxDocumentCollection_DocumentLoadedEventHandler(this.OnDocumentLoaded);
    TxApplication.ActiveDocument.Unloading -= new TxDocument_UnloadingEventHandler(this.OnActiveDocumentUnloading);
  }
}
